package com.feishi.core.util.poi.jxls;

import org.apache.commons.jexl2.parser.ParseException;
import org.slf4j.LoggerFactory;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.logging.Logger;

/**
 * @version 1.0
 * @auth caixq
 * @time 18-5-22 17:25
 **/
public class ObjectCollectionDemo {

    public static void main(String[] args) throws ParseException, IOException, java.text.ParseException {

        List<Employee> employees = generateSampleEmployeeData();
        OutputStream os = new FileOutputStream("target/object_collection_output.xls");
        Map<String , Object> model=new HashMap<String , Object>();
        model.put("employees", employees);
        model.put("nowdate", new Date());
        JxlsUtils.exportExcel(new FileInputStream("/tmp/object_collection_template.xls"), os, model);
        os.close();
    }

    public static List<Employee> generateSampleEmployeeData() throws ParseException, java.text.ParseException {
        List<Employee> employees = new ArrayList<Employee>();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MMM-dd", Locale.US);
        employees.add( new Employee("Elsa", dateFormat.parse("1970-Jul-10"), 1500, 0.15) );
        employees.add( new Employee("Oleg", dateFormat.parse("1973-Apr-30"), 2300, 0.25) );
        employees.add( new Employee("Neil", dateFormat.parse("1975-Oct-05"), 2500, 0.00) );
        employees.add( new Employee("Maria", dateFormat.parse("1978-Jan-07"), 1700, 0.15) );
        employees.add( new Employee("John", dateFormat.parse("1969-May-30"), 2800, 0.20) );
        return employees;
    }

    private static class Employee {
        public Employee(String elsa, Date parse, int i, double v) {

        }
    }
}

